package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.Loss;
import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.service.LossService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-09-29 23:25
 * 肖某的定损controller
 */
@CrossOrigin  //解决跨域
@RestController  //要求返回json格式数据异步使用
public class LossController {

    //获取service实例
    @Resource
    LossService lossService;

    //使用分页查询动态SQL
    @RequestMapping("/loss")
    public ResponseResult<PageBean<Loss>> fenyeLoss(Loss loss,int pageSize,int pageIndex){
      return lossService.selectLossByPageService(loss, pageIndex, pageSize);
    }

    //新增定损名单：
    @GetMapping("/loss")
    public String addLo(Loss loss){
        lossService.addLossService(loss);
        return "添加成功";
    }

    //修改定损名单
    @PostMapping("/loss")
    public String updataLo(Loss loss){
        lossService.updataLossService(loss);
        return "修改成功";
    }

    //删除定损名单
    @DeleteMapping("/loss")
    public String delete(int id){
        lossService.deleteLossService(id);
        return "删除成功";
    }
    //查询所有数据
    @GetMapping("selectAll")
    public List<Loss> selectAddController(){
        return lossService.selectAllLossService();
    }
}
